#include<algorithm>
#include<iostream>
#include<memory.h>
using namespace std;
int dp[1010][1010] = { 0 };
int main()
{
	int m, n;
	while (cin >> n >> m)
	{
		int x;
		for (int i = 1; i <= n; i++)
		{
			for (int j = 1; j <= m; j++)
			{
				cin >> x;
				dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]) + x;
			}
		}
		cout << dp[n][m]<<"\r\n";
		memset(dp, 0, sizeof(dp));
	}
	return 0;
}